/**
 * @author GaoYoubo
 * @since 2012-09-25
 * form元素的操作和处理
 */
if(typeof(mlog) === "undefined"){var mlog = function(){}};
mlog.dialog = {};
$.extend(mlog.dialog, {
	/**
	 * tip
	 * @param {} setting.msg 
	 * @param {} setting.type error, tip, success, warn
	 */
	tip : function(setting){
		if(setting === undefined){
			return;
		}
		if (setting.msg === undefined) {
			return;
		}
		if (setting.type === undefined) {
			setting.type = 'tips.gif';
		}
		
		var icon = 'tips.gif';
		if(setting.type == 'error'){
			icon = 'error.gif';
		}
		else if(setting.type == 'success'){
			icon = 'success.gif';
		}
		else if(setting.type == 'warn'){
			icon = 'alert.gif';
		}
		else {
			icon = 'tips.gif';
		}
		
		$.dialog({
			title : false,
			content : setting.msg,
			time : 1,
			min : false,
			max : false,
			icon : icon,
			// cancel: function(){},
			close : function() {
				var duration = 400, /* 动画时长 */
				api = this, opt = api.config, wrap = api.DOM.wrap, top = $(window).scrollTop() - wrap[0].offsetHeight;
				wrap.animate(
					{
						top : top + 'px',
						opacity : 0
					}, 
					duration, function() {
						opt.close = $.noop;
						api.close();
					}
				);
				return false;
			}
		});
	},
	
	notice: function(options){
		var opts = options || {},
        api, aConfig, hide, wrap, top,
        duration = opts.duration || 800;
        
	    var config = {
	        id: 'Notice',
	        left: '100%',
	        top: '100%',
	        fixed: true,
	        drag: false,
	        resize: false,
	        min : false,
			max : false,
	        init: function(here){
	            api = this;
	            aConfig = api.config;
	            wrap = api.DOM.wrap;
	            top = parseInt(wrap[0].style.top);
	            hide = top + wrap[0].offsetHeight;
	                        
	            wrap.css('top', hide + 'px')
	            .animate({top: top + 'px'}, duration, function(){
	                opts.init && opts.init.call(api, here);
	            });
	        },
	        close: function(here){
	            wrap.animate({top: hide + 'px'}, duration, function(){
	                opts.close && opts.close.call(this, here);
	                aConfig.close = $.noop;
	                api.close();
	            });
	                        
	            return false;
	        }
	    };
	    for(var i in opts) {
	        if( config[i] === undefined ) config[i] = opts[i];
	    }
	    return $.dialog( config );
	},
	
	
	showModelDialog : function(config){
		config.lock = true;
		config.close = mlog.dialog.closeAnimate;
		return $.dialog(config);
	}, 
	
	showDialog : function(config){
		config.close = mlog.dialog.closeAnimate;
		return $.dialog(config);
	},
	
	closeAnimate : function(){
		var duration = 400, /*动画时长*/
        api = this,
        opt = api.config,
        wrap = api.DOM.wrap,
        top = $(window).scrollTop() - wrap[0].offsetHeight;
        
	    wrap.animate({top:top + 'px', opacity:0}, duration, function(){
	        opt.close = function(){};
	        api.close();
	    });
	    return false;
	}, 
	
});